import { Row, Col } from "antd";
import * as React from "react";
import VirtualDeviceCondition, {
  VirtualDeviceConditionState,
} from "./compontents/VirtualDeviceCondition";
import VirtualDeviceTable from "./compontents/VirtualDeviceTable";
import { getComponentType } from "../deviceseversapi";
import { AjaxData } from "../../../../data/interface/publicInterface";
import "./index.less";

export interface VirtualDeviceProps {}

export interface VirtualDeviceState {
  query: VirtualDeviceConditionState;
  subItem: any[];
}

class VirtualDevice extends React.Component<
  VirtualDeviceProps,
  VirtualDeviceState
> {
  state = {
    query: { devVal: "", energyType: "", typeId: "" },
    subItem: [],
  };
  componentWillMount() {
    this.getSubType();
  }
  /**请求分项列表 */
  //获取分项类型下拉
  async getSubType() {
    try {
      let res: any = await getComponentType().catch((err) => {
        console.log(err);
      });
      const json: AjaxData = res;
      if (json.success) {
        this.setState({
          subItem: json.data,
        });
      }
    } catch (error) {}
  }
  render() {
    return (
      <div className="VirtualDevice">
        <Row>
          <Col span={24} style={{ paddingBottom: 12 }}>
            <VirtualDeviceCondition
              subItem={this.state.subItem}
              onSubmit={(data: VirtualDeviceConditionState) => {
                this.setState({ query: data });
              }}
            />
          </Col>
          <Col span={24}>
            <VirtualDeviceTable
              subItem={this.state.subItem}
              query={this.state.query}
            />
          </Col>
        </Row>
      </div>
    );
  }
}

export default VirtualDevice;
